import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { PersonalService } from './personal.service';
import { Profile } from './entities/profile.entity';
import { Image } from './entities/image.entity';
import { PersonalList } from './entities/personal-list.entity';

@Controller('personal')
export class PersonalController {
  constructor(private readonly personalService: PersonalService) { }
  // -------------------------- 个人信息接口 --------------------------
  @Post('profile')
  createProfile(@Body() data: Partial<Profile>): Promise<Profile> {
    return this.personalService.createProfile(data);
  }

  @Get('profile')
  getProfiles(): Promise<Profile[]> {
    return this.personalService.getProfiles();
  }

  @Get('profile/:id')
  getProfileById(@Param('id') id: string): Promise<Profile> {
    return this.personalService.getProfileById(+id);
  }

  @Patch('profile/:id')
  updateProfile(
    @Param('id') id: string,
    @Body() data: Partial<Profile>,
  ): Promise<Profile> {
    return this.personalService.updateProfile(+id, data);
  }

  @Patch('profile/:id/avatar') // 单独更换头像接口
  updateAvatar(
    @Param('id') id: string,
    @Body('avatarUrl') avatarUrl: string,
  ): Promise<Profile> {
    return this.personalService.updateAvatar(+id, avatarUrl);
  }

  @Delete('profile/:id')
  deleteProfile(@Param('id') id: string): Promise<void> {
    return this.personalService.deleteProfile(+id);
  }

  // -------------------------- 图片资源接口 --------------------------
  @Post('images')
  createImage(@Body() data: Partial<Image>): Promise<Image> {
    return this.personalService.createImage(data);
  }

  @Get('images')
  getImages(): Promise<Image[]> {
    return this.personalService.getImages();
  }

  @Get('images/:id')
  getImageById(@Param('id') id: string): Promise<Image> {
    return this.personalService.getImageById(+id);
  }

  @Patch('images/:id')
  updateImage(
    @Param('id') id: string,
    @Body() data: Partial<Image>,
  ): Promise<Image> {
    return this.personalService.updateImage(+id, data);
  }

  @Delete('images/:id')
  deleteImage(@Param('id') id: string): Promise<void> {
    return this.personalService.deleteImage(+id);
  }

  // -------------------------- 图文内容接口 --------------------------
  @Post('posts')
  createPost(@Body() data: Partial<PersonalList>): Promise<PersonalList> {
    return this.personalService.createPost(data);
  }

  @Get('posts')
  getPosts(): Promise<PersonalList[]> {
    return this.personalService.getPosts();
  }

  @Get('posts/:id')
  getPostById(@Param('id') id: string): Promise<PersonalList> {
    return this.personalService.getPostById(+id);
  }

  @Patch('posts/:id')
  updatePost(
    @Param('id') id: string,
    @Body() data: Partial<PersonalList>,
  ): Promise<PersonalList> {
    return this.personalService.updatePost(+id, data);
  }

  @Delete('posts/:id')
  deletePost(@Param('id') id: string): Promise<void> {
    return this.personalService.deletePost(+id);
  }

}
